package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ecable.bean.ProfileTO;
import com.ecable.bean.StateTO;
import com.ecable.delegate.StateMgrDelegate;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.util.UtilConstants;
import com.sun.org.apache.commons.beanutils.BeanUtils;

public class ViewRegStateAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RequestDispatcher rd = null;

		Vector<StateTO> vsto = null;
		String path = "";

		try {

			StateMgrDelegate smd = new StateMgrDelegate();

			vsto = smd.viewState();

			if (vsto != null) {

				request.setAttribute("villstate", vsto);
				// request.setAttribute("p", p);
				path = UtilConstants._REG_ADDRESS_PAGE;
				System.out.println(path);
				Iterator it = vsto.listIterator();
				while (it.hasNext()) {
					StateTO st = (StateTO) it.next();
					System.out.println(st.getSname());
				}
			} else {

				request
						.setAttribute("status",
								UtilConstants._Reg_STATES_FAILED);

				path = UtilConstants._LOGIN_FAILED_PAGE;

			}
		}

		catch (ConnectionException ce) {
			throw new ServletException("server busy please try again");
		}

		catch (DataNotFoundException le) {
			request.setAttribute("status", UtilConstants._ALL_STATES_FAILED);
			rd = request.getRequestDispatcher(UtilConstants._LOGIN_FAILED_PAGE);
		}
		System.out.println(path);
		rd = request.getRequestDispatcher(path);
		rd.forward(request, response);

	}
}
